package cn.maxhou.test;

import cn.maxhou.entity.Auction;
import cn.maxhou.entity.User;
import cn.maxhou.mapper.AuctionMapper;
import cn.maxhou.mapper.UserMapper;
import cn.maxhou.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class test {
    @Test
    public  void insert(){
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        User user = new User("侯慧聪","h8889518","8888888888888888","17373572868","郴州市","99999");
        sqlSession.getMapper(UserMapper.class).insert(user);
        sqlSession.commit();
    }

    @Test
    public void checkusername(){
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        int count = userMapper.checkusername("侯慧聪");
        System.out.println(count);
    }

    @Test
    public void testLogin(){
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        int result = userMapper.isAdmin("h8885918");
        int result2 = userMapper.checkusername("h8885918");
        int result3 = userMapper.userlogin("h8885918","h888951");
        System.out.println(result3);
    }

    @Test
    public void getAuctionList(){
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        AuctionMapper auctionMapper = sqlSession.getMapper(AuctionMapper.class);
        List<Auction> auctionList = auctionMapper.getAuctionList();
        for (Auction auction : auctionList) {
            System.out.println(auction);
        }
    }

    @Test
    public void delAuction(){
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        AuctionMapper auctionMapper = sqlSession.getMapper(AuctionMapper.class);
        int i = auctionMapper.deleteAuction(21);

        System.out.println(i);
    }

    @Test
    public void insertAuction(){
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        AuctionMapper auctionMapper = sqlSession.getMapper(AuctionMapper.class);
        Auction auction = new Auction();
        auction.setAuctionId(1);
        //auction.set;
        auctionMapper.insertAuction(auction);
    }
}
